package com.knowledge.review.designPatterns.creatormode.factorypattern.simplefactory;

import org.jetbrains.annotations.Nullable;

/**
 * @author XFW
 * @date 2024/5/6 11:12
 * @Description 简单工厂实现
 **/
public class SimpleFactoryPattern {
    public static void main(String[] args) {
        Product product = SimpleFactory.makeProduct(2);
        product.show();
    }


    /**
     * 抽象产品
     */
    public interface Product {
        void show();
    }


    /**
     * 具体产品：ProductA
     */
    static class ConcreteProduct1 implements Product {
        @Override
        public void show() {
            System.out.println("具体产品1显示...");
        }
    }

    /**
     * 具体产品：ProductB
     */
    static class ConcreteProduct2 implements Product {
        @Override
        public void show() {
            System.out.println("具体产品2显示...");
        }
    }

    /**
     * 具体产品：ProductC
     */
    static class ConcreteProduct3 implements Product {
        @Override
        public void show() {
            System.out.println("具体产品3显示...");
        }
    }

    /**
     * 主要变量信息
     */
    final class Const {
        static final int PRODUCT_A = 0;
        static final int PRODUCT_B = 1;
        static final int PRODUCT_C = 2;
    }

    /**
     * 简单工厂
     */
    static class SimpleFactory {
        public static @Nullable Product makeProduct(int kind) {
            switch (kind) {
                case Const.PRODUCT_A:
                    return new ConcreteProduct1();
                case Const.PRODUCT_B:
                    return new ConcreteProduct2();
                case Const.PRODUCT_C:
                    return new ConcreteProduct3();
            }
            return null;
        }
    }
}
